import sqlite3
#连接数据库
conn = sqlite3.connect("book.db")
#创建游标
cursor = conn.cursor()
#创建表
# sql = '''create table if not exists sys_user(
#                   id int(111) primary key,
#                   name varchar(25),
#                   age int(3)
#                 )'''
# cursor.execute(sql)
# conn.commit()

#插入数据
# insert_sql = "insert into sys_user(id,name,age) values (?,?,?)"
# cursor.execute(insert_sql,(1,"root1",18))
# cursor.execute(insert_sql,(2,"root2",18))
# cursor.execute(insert_sql,(3,"root3",18))
# cursor.execute(insert_sql,(4,"root4",18))
# conn.commit()

#查询数据
select_sql = "select * from sys_user"
# cursor.execute(select_sql)
# for row in cursor:
#     print(row)

# cursor.execute(select_sql)
# # result = cursor.fetchone()
# # result = cursor.fetchmany(3)
# result = cursor.fetchall()
# print(result)

update_sql = "update sys_user set name=? where id=?"
cursor.execute(update_sql,("admin",1))
conn.commit()

delete_sql = "delete from sys_user where id=?"
cursor.execute(delete_sql,(4,))
conn.commit()

cursor.execute(select_sql)
for row in cursor:
    print(row)
import pymysql
conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='book')
cursor = conn.cursor()
cursor.execute("select * from book_info")
for row in cursor:
    print(row)